package com.xxw.yygh.hosp.controller.user;


import com.xxw.yygh.common.result.R;
import com.xxw.yygh.hosp.service.HospitalService;
import com.xxw.yygh.model.hosp.Hospital;
import com.xxw.yygh.vo.hosp.HospitalQueryVo;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/user/hosp/hospital")
public class UserHospitalController {

    @Resource
    private HospitalService hospitalService;

    //用户首页医院列表展示（不分页）
    @GetMapping("/list")
    public R getHospitalList(HospitalQueryVo hospitalQueryVo){
        //与管理员页面共用一个方法，实际不用分页，所以分页数据写死（只展示一列）
        Page<Hospital> page = hospitalService.getHospitalPage(1, 10000000, hospitalQueryVo);
        return R.ok().data("list",page.getContent());
    }

    //根据医院名字进行模糊查询
    @GetMapping("/{name}")
    public R findByName(@PathVariable String name){
        List<Hospital> list=hospitalService.findByNameLike(name);
        return R.ok().data("list",list);
    }

    //医院详情
    @GetMapping("/detail/{hoscode}")
    public R getHospitalDetail(@PathVariable String hoscode){
        Hospital hospital=hospitalService.getHospitalDetail(hoscode);
        return R.ok().data("hospital",hospital);
    }

}
